using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EagleContoller : EnemiesController
{
    
    //private Animator anim;
    private Rigidbody2D rb;

    public Transform topPoint,bottomPoint;
    private float topY,bottomY;
    public Collider2D coll;
    public LayerMask ground;

    private bool isUp = true;
    public float Spend;

    // Start is called before the first frame update
    protected override void Start()
    {
        base.Start();
        rb = GetComponent<Rigidbody2D>();
        //anim = GetComponent<Animator>();
        // transform.DetachChildren();
        topY = topPoint.position.y;
        bottomY = bottomPoint.position.y;
        Destroy(topPoint.gameObject);
        Destroy(topPoint.gameObject);
    }

    // Update is called once per frame
    void Update()
    {
        Movement();
    }

    void Movement(){
        if(isUp){
            if(transform.position.y > topY){
               isUp = false;
            }else{
                rb.velocity = new Vector2(rb.velocity.x,Spend);
            }
        }
        else{
           if(transform.position.y < bottomY){
               isUp = true;
            }else{
                rb.velocity = new Vector2(rb.velocity.x,-Spend);
            }
        }
    }

}
